<?php


namespace Xiaoguai\DesignPattern\DP006;


class MyAggregate implements AggregateInterface
{

    protected $list = [];

    public function add($object)
    {
        $this->list[] = $object;
    }

    public function remove($object)
    {
        $i = array_search($object, $this->list, true);
        if ($i !== false) {
            array_splice($this->list, $i, 1);
        }
    }

    public function getIterator(): IteratorInterface
    {
        return new MyIterator($this->list);
    }
}